home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
4490
/
4490.xpi
/
components
/
scripts
/
gmail.js
< prev
next >
Wrap
Text File
|
2010-01-25
|
4KB
|
116 lines
/***********************************************************
Gmail
***********************************************************/
var hostString="gmail.com";
var supportInboxOnly=true;
var supportShowFolders=true;
function init(){
this.initStage=ST_PRE;
var ar=this.user.split("@");
if(ar[1]=="gmail.com"||ar[1]=="googlemail.com"){
this.loginData=["https://www.google.com/accounts/ServiceLoginAuth?service=mail",
"Email","Passwd",
"continue=https%3A%2F%2Fmail.google.com%2Fmail%2F"];
this.dataURL="https://mail.google.com/mail";
this.mailURL="https://mail.google.com/mail";//used in below process!
this.mailDomain=".+?.google.com";
if(this.getCookie("google.com","SID")!=null)this.loginData[3]+="&PersistentCookie=yes";
}else{//Google Apps
this.dataURL="https://mail.google.com/a/"+ar[1];
this.mailURL="https://mail.google.com/a/"+ar[1];//used in below process!
this.mailDomain=".+?.google.com";
this.loginData=["https://www.google.com/a/"+ar[1]+"/LoginAction2?service=mail",
"","Passwd",
"continue="+encodeURIComponent(this.mailURL)+"&service=mail&Email="+encodeURIComponent(ar[0])];
}
}
function getIconURL(){
return "http://mail.google.com/favicon.ico";
}
function process(aHttpChannel, aData) {
switch(this.stage){
case ST_PRE:
this.getHtml(this.mailURL);
return false;
case ST_PRE_RES:
var fnd=aData.match(/GALX[\s\S]+?value=\"(\S+?)\"/);
if(fnd){
this.stage=ST_LOGIN;
this.getHtml(this.loginData[LOGIN_URL],this.loginData[LOGIN_POST]+"&GALX="+encodeURIComponent(fnd[1]));
return false;
}
this.onError();
return true;
case ST_LOGIN_RES:
var fnd=aData.match(/<meta.+?url=(?:'|')(\S+)(?:'|')/);
if(fnd){
fnd=fnd[1].replace(/&/g,"&");
this.getHtml(fnd);
return false;
}
++this.stage;//Google Apps
case (ST_LOGIN_RES+1):
var fnd=aData.match(/GLOBALS=\[(?:(.*?),){10}/);
if(fnd){
fnd=fnd[1].replace(/\"/g,"");
this.dataURL=this.mailURL+"/?ui=2&ik="+fnd+"&view=tl&start=0&num=25&rt=h&as_has=is%3Aunread&as_subset="+(this.inboxOnly?"inbox":"all")+"&search=adv";
this.newUI=true;
}else{
this.dataURL=this.mailURL+"/?ui=1&view=tl&search=query&start=0&q=is%3Aunread"+(this.inboxOnly?"%20in%3Ainbox":"");
this.newUI=false;
}
this.stage=ST_DATA;
break;
}
return this.baseProcess(aHttpChannel, aData);
}
function getCount(aData){
var fnd;
if(this.newUI){
if(this.inboxOnly)fnd=aData.match(/"ld",\[\["\^i",(\d+)/);
else fnd=aData.match(/D\(\["ti",.+?,(\d+)/);
}else{
if(this.inboxOnly)fnd=aData.match(/"ds",\[\["inbox",(\d+)/);
else fnd=aData.match(/D\(\["ts",\d*,\d*,(\d+)/);
}
if(fnd){
return fnd[1];
}else{
return -1;
}
}
function getDesc(){
var n=this.calcCount();
if(this.inboxOnly)return n>=0?n:"";
else return n>=100?"~"+n:(n>=0?n:"");
}
function getMailURL(aFolder){
if(aFolder){
if(this.newUI)return this.mailURL+"/#label/"+encodeURIComponent(aFolder);
else return this.mailURL+"/?s=l&l="+encodeURIComponent(aFolder);
}
return this.mailURL;
}
function getData(aData){
var obj={};
if(!this.showFolders)return obj;
var fnd;
if(this.newUI)fnd=aData.match(/\["ld"\s*,\s*\[(?:,?\[.+?\]\n)+\]\n,\[((?:,?\[.+?\]\n)+)\]\n\]\n\)/);
else fnd=aData.match(/\["ct"\s*,\s*\[([\s\S]*?)\]\n\]\n\)/);
if(fnd){
var re=/\[\"(.+)\"\s*,\s*(\d+)/g;
var o;
var ar=[];
while ((o = re.exec(fnd[1])) != null){
if(parseInt(o[2])>0){
ar.push(o[1]);
ar.push(o[2]);
}
}
if(ar)obj.folders=encodeArray(ar);
}
return obj;
}